﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Xml.Serialization;
using WebChatApi.Common.Interface;

/// <summary>
/// The Common namespace.
/// </summary>
namespace WebChatApi.Common
{
    /// <summary>
    /// Abstract class for base object, with key, created stamp and last updated stamp.
    /// </summary>
    [DataContract]
    public abstract class BaseObject : IIdentifiable
    {
        /// <summary>
        /// Gets or sets the key.
        /// </summary>
        /// <value>The key.</value>
        [DataMember]
        public Guid Key
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the created stamp.
        /// This value is as same as value in property <c>CreatedStampString</c>.
        /// And this property will be used to business logics and WCF XML serialization.
        /// So if you are using JSON format, please use <c>CreatedStampString</c>.
        /// </summary>
        /// <value>The created stamp.</value>
        [DataMember]
        public DateTime CreatedStamp
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the last updated stamp.
        /// This value is as same as value in property <c>LastUpdatedStampString</c>.
        /// And this property will be used to business logics and WCF XML serialization.
        /// So if you are using JSON format, please use <c>LastUpdatedStampString</c>.
        /// </summary>
        /// <value>The last updated stamp.</value>
        [DataMember]
        public DateTime LastUpdatedStamp
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the created stamp string.
        /// Format: yyyy-MM-ddTHH:mm:ss.fffzzz
        /// Sample: 2013-01-02T03:45:23.215+08:00
        /// This value is as same as value in property <c>CreatedStamp</c>.
        /// And this property will be only used to JSON format serialization.
        /// So if the property is used to business logics and WCF XML serialization, please use <c>CreatedStamp</c>.
        /// </summary>
        /// <value>The created stamp string.</value>
        public string CreatedStampString
        {
            get
            {
                return DateTimeUtil.DateTimeToFullString(this.CreatedStamp);
            }
            set
            {
                this.CreatedStamp = DateTimeUtil.FullStringToDateTime(value, this.CreatedStamp);
            }
        }


        /// <summary>
        /// Gets or sets the last updated stamp string.
        /// Format: yyyy-MM-ddTHH:mm:ss.fffzzz
        /// Sample: 2013-01-02T03:45:23.215+08:00
        /// This value is as same as value in property <c>LastUpdatedStamp</c>.
        /// And this property will be only used to JSON format serialization.
        /// So if the property is used to business logics and WCF XML serialization, please use <c>LastUpdatedStamp</c>.
        /// </summary>
        /// <value>The last updated stamp string.</value>
        public string LastUpdatedStampString
        {
            get
            {
                return DateTimeUtil.DateTimeToFullString(this.LastUpdatedStamp);
            }
            set
            {
                this.LastUpdatedStamp = DateTimeUtil.FullStringToDateTime(value, this.LastUpdatedStamp);
            }
        }

        /// <summary>
        /// Gets or sets the State.
        /// </summary>
        /// <value>The State.</value>
        [DataMember]
        public ObjectState State
        {
            get;
            set;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="BaseObject" /> class.
        /// </summary>
        public BaseObject()
        {
            this.Key = Guid.NewGuid();
            this.LastUpdatedStamp = this.CreatedStamp = DateTime.UtcNow;
        }
    }
}
